<?php
	
	$CID 	= _GET('cid');
	$SID 	= _GET('sid');
	$HASH 	= _GET('hash');
	$LNK 	= _GET('lnk');
	$CHNG 	= _GET('chng');
	$SLID 	= _GET('slid');
	$CSID 	= _GET('csid');
	
	if ( empty($LNK) ) {
		$defaultSections = $STUD->getDefaultSections($CID, '', $SLID);
		if (!empty($defaultSections)) {
				
			if ( !empty($CHNG)) {
				if ( ($_SESSION['WB_AccType'] == 'S') || ($_COOKIE['WB_Account'] == 'S') ) {
					$changeSection = '<div class="change-section-button" onclick="changeSection(\'' . $logUserID . '\', \'' . $CID . '\', \'' . $SLID . '\', \'' . $activeYear . '\',\'' . $CSID . '\',\'' . $SID . '\')">SEND REQUEST TO CHANGE SCHEDULE</div>';
				}
			}
			
			$schedulePerSection = ( !empty($deanURI) ) ? $deanURI : 'SchedulePerSection';
			$sectionHTML = '<div class="div-reg-schedule"><ul class="ul-reg-schedule">';
			foreach($defaultSections as $defaultSectionsValue) {
				$sectionHTML .= '<li class="li-reg-schedule" onclick="showLoading(); linkNewPage(\'' . $schedulePerSection . '&cid=' . $CID . '&csid=' . $CSID . '&hash=' . hashRandom($HASH . $defaultSectionsValue['section_desc']) . '&sid=' . $defaultSectionsValue['section_idPK'] . '&slid=' . $SLID . '&chng=1\')">' . $defaultSectionsValue['section_desc'] . '</li>';
			}
			$sectionHTML .= '</ul></div>' . $changeSection;
	
		}
	}
	
	$sectionsDescription = $STUD->getDefaultSections($CID, $SID);
	$sectionDesc 		 =  $sectionsDescription[0]['section_desc'];
	
	if ( empty($SID) ) {
		$SID = $sectionsDescription[0]['section_idPK'];
	}
	
	$scheduleDefaultTime = $STUD->getScheduleDefaultTime(array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'), $activeYear);
	$timeCount  = 0;
	$bgcolor 	= LOOPING_F0F;
	if (!empty($scheduleDefaultTime)) {
		
		$scheduleHTML = '<table width="0" border="0" cellspacing="0" cellpadding="0" class="schedule-table">
						 <tr>
							<td width="120" height="25" class="schedule-label schedule-label-right" colspan="3">&nbsp;</td>
							<td width="105" class="schedule-label schedule-label-right">Monday</td>
							<td width="105" class="schedule-label schedule-label-right">Tuesday</td>
							<td width="105" class="schedule-label schedule-label-right">Wenesday</td>
							<td width="105" class="schedule-label schedule-label-right">Thursday</td>
							<td width="105" class="schedule-label schedule-label-right">Friday</td>
							<td width="105" class="schedule-label">Saturday</td>
						 </tr>';
						 
		$timeScheduleFrom = $STUD->getTimeSchedule('sched_from', $activeYear, 1);
		$timeScheduleTo   = $STUD->getTimeSchedule('sched_to', $activeYear, 1);
		
		foreach($scheduleDefaultTime as $scheduleDayField => $scheduleDay) {
			$scheduleHTML .= '<tr align="center" ' . $bgcolor . '><td width="50" class="schedule-label-time"><div>' . date("h:i", strtotime($timeScheduleFrom[$timeCount])) . '</div><div style="font-weight:normal; font-style:italic; font-size:12px;">' . date("a", strtotime($timeScheduleFrom[$timeCount])) . '</div></td><td width="20" class="schedule-label-time"> - </td><td width="50" class="schedule-label-time schedule-label-right"><div>' . date("h:i", strtotime($timeScheduleTo[$timeCount])) . '</div><div style="font-weight:normal; font-style:italic; font-size:12px;">' . date("a", strtotime($timeScheduleTo[$timeCount])) . '</div></td>';
			$rightCount = 1;
			$countDay   = count($scheduleDay);
			foreach($scheduleDay as $scheduleTimeField => $scheduleTime) {
				$clasRight = ($rightCount == $countDay) ? '' : 'schedule-time-right';
				if ($scheduleTime['sched_break'] == 'Y') {
					$sched = '<span class="font-red"><strong>LUNCH</strong></span>';
				}
				else {
					$sectionSubjectGenerateSchedules = $STUD->getSectionSubjectGenerateSchedules($SID, $scheduleTime['sched_time_idPK'], $activeYear); # CHANGE
					
					$sched = '';
					if ( !empty($sectionSubjectGenerateSchedules) ) {
						switch($profSubjectGenerateSchedules['lec_lab_both']) {
							case '0': $lecLabBoth = '(<em>lec</em>)'; break;
							case '1': $lecLabBoth = '(<em>lab</em>)'; break;
							case '2': $lecLabBoth = '(<em>lec/lab</em>)'; break;
						}
						if ( $sectionSubjectGenerateSchedules['is_saturday'] == 'N' ) {
							$sched .= '<div><strong>' . upperCase(substr($sectionSubjectGenerateSchedules['first_name'],0,1)) . '. ' . upperCase($sectionSubjectGenerateSchedules['last_name']) . '</strong></div>';
							$sched .= '<div>' . $sectionSubjectGenerateSchedules['room_desc'] . '</div>';
							$sched .= '<div>' . $lecLabBoth . '</div>';
						}
						$sched .= '<div><strong>' . $sectionSubjectGenerateSchedules['subj_code'] . '</strong></div>';
					}
					else {
						$sched = '&nbsp;';
					}
				}
				$scheduleHTML .= '<td class="schedule-time ' . $clasRight . '" height="75" align="center">' . $sched . '</td>';
				$rightCount++;
			}
			$scheduleHTML .= '</tr>';
			$bgcolor = ($bgcolor == LOOPING_F0F) ? LOOPING_FFF : LOOPING_F0F;
			$timeCount++;
		}
		$scheduleHTML .= '<tr><td height="5" class="schedule-label-right" colspan="3"></td><td colspan="6"></td></tr></table>';
		
		$profSubjSchedActive = $STUD->getProfSubjSchedActive($activeYear);
		if ( $profSubjSchedActive == 0 ) {
			$scheduleHTML .= '<div class="preview-schedule" style="margin-top:8px;"><div><span id="schedule_change_time" onclick="changeTimeScheduleActive(\'' . $activeYear . '\');">CHANGE THIS TIME SCHEDULE</span></div></div>';
		}
	}
	else {
		$tempSchedule = $STUD->getTempSchedule($activeYear);
		if ( empty($tempSchedule) ) {
			$scheduleHTML = '<div class="change-section-button"><div class="set-time-schedule" onclick="setTimeSchedule(\'' . $activeYear . '\');">SET TIME FOR MONDAY - SATURDAY SCHEDULE</div></div><div id="set_time_schedule"></div>';
		}
		else {
			$scheduleActive = 1;
			$scheduleHTML = '<div class="change-section-button"><div class="set-time-schedule">Temporary Time Schedule</div></div><div id="set_time_schedule"></div>';
		}
	
	}
	
	$getCourse 	  = $DSC->getCourse($CID);
	if(!empty($getCourse)) {
		$course_label	= $getCourse['course_desc'] . ' (' . $getCourse['course_code'] . ')';
	}
	$TEMP->set_var(array('prof_name' 		=> $profName,
						 'time_table'		=> $scheduleHTML,
						 'time_active'		=> $scheduleActive,
						 'year_id'			=> $activeYear,
						 'save_sched'		=> $saveSched,
						 'cid'				=> $CID,
						 'course_label'		=> $course_label,
						 'section_html'		=> $sectionHTML,
						 'section_desc'		=> $sectionDesc,
						 'sy_label'			=> $__SYR__
						));
?>